﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace K9Nano.Exceptions;

/// <summary>
/// A friendly exception that can be shown to the user. It will not be logged.
/// </summary>
[Serializable]
public class FriendlyException : Exception
{
    public int Error { get; set; }

    public FriendlyException() { }

    public FriendlyException(string message, int error = 400) : base(message)
    {
        Error = error;
    }
    public FriendlyException(string message, Exception inner, int error = 400) : base(message, inner)
    {
        Error = error;
    }

    public static FriendlyException BadRequest(string message)
    {
        return new FriendlyException(message);
    }

    public static FriendlyException Forbidden(string message)
    {
        return new FriendlyException(message, 403);
    }

    public static FriendlyException Forbidden()
    {
        return new FriendlyException("您没有访问权限", 403);
    }
}